home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / graphic / pvquan16.zip / ANIMDAT / BTREE.H < prev    next >
C/C++ Source or Header  |  1992-11-30  |  2KB  |  46 lines

  1. /*--------------------------------------------------------------*/
  2. /*            ANIMDAT 1.1                */
  3. /*        copyright 1992 - TODD SANKEY            */
  4. /*                                */
  5. /*  The author hereby grants permission for the use and sharing    */
  6. /* of both source code end executable versions of this software    */
  7. /* at no charge. This software is not for sale and no other    */
  8. /* shall charge for it without the expressed consent of the    */
  9. /* author.                            */
  10. /*                                */
  11. /*  The source code can be freely modified, but it must retain    */
  12. /* the original copyright notice, and the author must be    */
  13. /* notified of these changes if the altered code is to be    */
  14. /* distributed.                            */
  15. /*--------------------------------------------------------------*/
  16. /*------------------------------------------------------*/
  17. /* btree.h    Routines for creating a binary tree    */
  18. /*        based on an expression.            */
  19. /*------------------------------------------------------*/
  20.  
  21. #ifndef btree_h
  22. #define btree_h
  23.  
  24. /* Possible node types */
  25. typedef enum { NAMEDVAR, BINARYOP, UNARYOP, NUMBERVAL } node_types;
  26.  
  27. /* Node data structure */
  28. typedef struct btree_node_s {
  29.                 node_types    node_type;
  30.                 union    {
  31.                     char        *name;
  32.                     TOKEN_CODE    operator;
  33.                     double        value;
  34.                     } node_data;
  35.                 struct btree_node_s    *left;
  36.                 struct btree_node_s    *right;
  37.                 } btree_node , *btree_node_ptr;
  38.  
  39.  
  40. /* Interface routines for creating and evaluating a tree */
  41. btree_node_ptr    expression(void);
  42. void        display_btree(btree_node_ptr btree);
  43. double        eval_btree(btree_node_ptr btree);
  44. void        traverse_btree(btree_node_ptr btree, void (*f)(btree_node_ptr));
  45. #endif
  46.